<!DOCTYPE html>
<html lang="en">
<head>
    <title>公司考勤列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style style="text/css">
        .table-width {
            width: 420px;
        }
        .row {
            margin-right: -15px;
            margin-left: 0px;
        }

        .col-md-12 {
            padding-left: 0;
        }
    </style>
</head>
<body>
<section v-cloak class="content" id="app">
    <div class="nav-tabs-custom oaReportNav">
        <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;">
            <li class="active"><a href="#revenue-chart" data-toggle="tab">今日</a></li>
            <li><a href="#revenue-chart" data-toggle="tab">本月</a></li>
            <li v-for="(item,i) in months"><a href="#sales-chart" data-toggle="tab">{{item}}</a></li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover table-bordered text-center table-width">
                <thead>
                <tr>
                    <th style="width: 100px">公司</th>
                    <th style="width: 80px">应出勤</th>
                    <th style="width: 80px">出勤</th>
                    <th style="width: 80px">请假</th>
                    <th style="width: 80px">缺勤</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item,i) in list">
                    <td style="color:#169BD5;cursor: pointer" @click="signInDepartList(item)">
                        {{item.companyName}}
                    </td>
                    <td>
                        {{item.shouldCount}}
                    </td>
                    <td>
                        {{item.signInCount}}
                    </td>
                    <td>
                        {{item.leaveCount}}
                    </td>
                    <td style="color: red;">{{item.lackCount}}</td>
                </tr>
                <tr>
                    <td>合计</td>
                    <td>{{total.shouldCountTotal}}</td>
                    <td>{{total.signInCountTotal}}</td>
                    <td>{{total.leaveCountTotal}}</td>
                    <td style="color:red;">{{total.lackCountTotal}}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=6348cbbc"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/highcharts/highcharts.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            list: [],
            months: [],
            userId: getCurrentUser().id,
            time: "",
            isToday: "1",
            total: [{"shouldCountTotal": 0, "signInCountTotal": 0, "leaveCountTotal": 0, "lackCountTotal": 0}]
        },
        methods: {
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            getMonths: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.months.push(that.insert_flg(dateTime, "-", "4"))
                }
            },
            insert_flg: function (str, flg, sn) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    console.log(tmp)
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                return newstr;
            },
            getList: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.system.signIn.getSignInCompanyManagerList, {
                    isToday: that.isToday,
                    signInMonth: that.time
                }, function (data) {
                    that.list = data;
                    that.getAllTotal(that.list);
                }, true);
            },
            signInDepartList: function (item) {
                var that = this;
                url = "/reportForm/signIn/departList.html?flag=1&companyId=" + item.companyId + "&companyName=" + item.companyName + "&time=" + that.time + "&isToday=" + that.isToday;
                top.closeTabByPageId("signIn-departList");
                top.addTabs({id: "signIn-departList", title: item.companyName, close: true, url: url});
            },
            getCount:function (arr,key) {
                var number=0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number+=(arr[i][key]?arr[i][key]:0);
                }
                return number;
            },
            getAllTotal:function (list) {
                var that = this;
                that.total.shouldCountTotal = that.getCount(list,"shouldCount");
                that.total.signInCountTotal = that.getCount(list,"signInCount");
                that.total.leaveCountTotal = that.getCount(list,"leaveCount");
                that.total.lackCountTotal = that.getCount(list,"lackCount");
            }
        },
        mounted: function () {
            //获取前5个月
            this.getMonths();
            var that = this;
            that.getList();
            that.time = new Date().Format("yyyy-MM");
            $("body").delegate(".nav-tabs li a", "click", function () {
                var dateTime = $(this).text();
                if (dateTime == "本月") {
                    that.isToday = "0";
                    that.time = new Date().Format("yyyy-MM");
                } else if (dateTime == "今日") {
                    that.isToday = "1";
                    that.time = new Date().Format("yyyy-MM-dd");
                } else {
                    that.isToday = "0";
                    that.time = dateTime;
                }
                that.getList();
            });
        }

    });
</script>

</body>
</html>